<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Substitutions (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Substitutions (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Substitutions (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Mode-Iterators.html" rel="up" title="Mode Iterators">
<link href="Examples.html" rel="next" title="Examples">
<link href="Defining-Mode-Iterators.html" rel="prev" title="Defining Mode Iterators">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="subsubsection-level-extent" id="Substitutions">
<div class="nav-panel">
<p>
Next: <a href="Examples.html" accesskey="n" rel="next">Mode Iterator Examples</a>, Previous: <a href="Defining-Mode-Iterators.html" accesskey="p" rel="prev">Defining Mode Iterators</a>, Up: <a href="Mode-Iterators.html" accesskey="u" rel="up">Mode Iterators</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsubsection" id="Substitution-in-Mode-Iterators"><span>17.23.1.2 Substitution in Mode Iterators<a class="copiable-link" href="#Substitution-in-Mode-Iterators"> &para;</a></span></h4>
<a class="index-entry-id" id="index-define_005fmode_005fattr"></a>

<p>If an <samp class="file">.md</samp> file construct uses mode iterators, each version of the
construct will often need slightly different strings or modes.  For
example:
</p>
<ul class="itemize mark-bullet">
<li>When a <code class="code">define_expand</code> defines several <code class="code">add<var class="var">m</var>3</code> patterns
(see <a class="pxref" href="Standard-Names.html">Standard Pattern Names For Generation</a>), each expander will need to use the
appropriate mode name for <var class="var">m</var>.

</li><li>When a <code class="code">define_insn</code> defines several instruction patterns,
each instruction will often use a different assembler mnemonic.

</li><li>When a <code class="code">define_insn</code> requires operands with different modes,
using an iterator for one of the operand modes usually requires a specific
mode for the other operand(s).
</li></ul>

<p>GCC supports such variations through a system of &ldquo;mode attributes&rdquo;.
There are two standard attributes: <code class="code">mode</code>, which is the name of
the mode in lower case, and <code class="code">MODE</code>, which is the same thing in
upper case.  You can define other attributes using:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_mode_attr <var class="var">name</var> [(<var class="var">mode1</var> &quot;<var class="var">value1</var>&quot;) ... (<var class="var">moden</var> &quot;<var class="var">valuen</var>&quot;)])
</pre></div>

<p>where <var class="var">name</var> is the name of the attribute and <var class="var">valuei</var>
is the value associated with <var class="var">modei</var>.
</p>
<p>When GCC replaces some <var class="var">:iterator</var> with <var class="var">:mode</var>, it will scan
each string and mode in the pattern for sequences of the form
<code class="code">&lt;<var class="var">iterator</var>:<var class="var">attr</var>&gt;</code>, where <var class="var">attr</var> is the name of a
mode attribute.  If the attribute is defined for <var class="var">mode</var>, the whole
<code class="code">&lt;&hellip;&gt;</code> sequence will be replaced by the appropriate attribute
value.
</p>
<p>For example, suppose an <samp class="file">.md</samp> file has:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_mode_iterator P [(SI &quot;Pmode == SImode&quot;) (DI &quot;Pmode == DImode&quot;)])
(define_mode_attr load [(SI &quot;lw&quot;) (DI &quot;ld&quot;)])
</pre></div>

<p>If one of the patterns that uses <code class="code">:P</code> contains the string
<code class="code">&quot;&lt;P:load&gt;\t%0,%1&quot;</code>, the <code class="code">SI</code> version of that pattern
will use <code class="code">&quot;lw\t%0,%1&quot;</code> and the <code class="code">DI</code> version will use
<code class="code">&quot;ld\t%0,%1&quot;</code>.
</p>
<p>Here is an example of using an attribute for a mode:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_mode_iterator LONG [SI DI])
(define_mode_attr SHORT [(SI &quot;HI&quot;) (DI &quot;SI&quot;)])
(define_insn ...
  (sign_extend:LONG (match_operand:&lt;LONG:SHORT&gt; ...)) ...)
</pre></div>

<p>The <code class="code"><var class="var">iterator</var>:</code> prefix may be omitted, in which case the
substitution will be attempted for every iterator expansion.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Examples.html">Mode Iterator Examples</a>, Previous: <a href="Defining-Mode-Iterators.html">Defining Mode Iterators</a>, Up: <a href="Mode-Iterators.html">Mode Iterators</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
